namespace Maple.Branch.Settings.Providers
{
    using System.Threading.Tasks;
    using Microsoft.Extensions.Configuration;
    using Volo.Abp;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.Settings;

    public class ConfigurationSettingProvider : IBranchSettingProvider, ITransientDependency
    {
        public string Name => ConfigurationSettingValueProvider.ProviderName;

        protected IConfiguration Configuration { get; }

        public ConfigurationSettingProvider(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public virtual Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey)
        {
            return Task.FromResult(Configuration[ConfigurationSettingValueProvider.ConfigurationNamePrefix + setting.Name]);
        }

        public virtual Task SetAsync(SettingDefinition setting, string value, string providerKey)
        {
            throw new AbpException($"Can not set a setting value to the application configuration.");
        }

        public virtual Task ClearAsync(SettingDefinition setting, string providerKey)
        {
            throw new AbpException($"Can not set a setting value to the application configuration.");
        }
    }
}
